package com.tvsinfo.suanfa;

/**
 * 对于一个由0..n的所有数按升序组成的序列，我们要进行一些筛选，每次我们取当前所有数字中从小到大的第奇数位个的数，并将其丢弃。重复这一过程直到最后剩下一个数。请求出最后剩下的数字。
 */
public class Demo3 {

    public static void main(String[] args) {
        Demo3 demo3 = new Demo3();
        demo3.todoMethod(new int[]{1, 2, 3, 4, 5, 6,7, 8, 9,10,11,12,13,15,16,19});
        demo3.todoMethod(new int[]{10, 20, 31, 45, 56, 68,70, 80,81});
        demo3.todoMethod(new int[]{23, 24, 56, 57,58, 66, 68,70, 80});
        demo3.todoMethod(new int[]{100, 211, 311, 415, 516, 628,750, 810});
        demo3.todoMethod(new int[]{0, 500, 600, 700, 900, 915,955, 1000});

    }

    public int todoMethod(int[] paraArray) {
        for (int i = 0; i < paraArray.length; i++) {
            System.out.print(""+paraArray[i]+" ,");
        }
        System.out.println();
        System.out.println("---------");
        if (paraArray.length == 1) {
            System.out.println(paraArray[0]);
            System.out.println();
            System.out.println();
            return paraArray[0];
        }
        int length = paraArray.length % 2;
        int[] bb = new int[paraArray.length / 2 ];
        int b = 0;
        for (int i = 1; i <= paraArray.length ; i++) {
            //偶数
            if (i % 2 == 0) {
                bb[b] = paraArray[i-1];
                b++;
                continue;
            }
        }
        return todoMethod(bb);
    }


}
